this.ws=this.ws||{};
(function(){
    var VScrollBar=function($dom)
    {
        this.init($dom);
    }

    var p=VScrollBar.prototype;
    p.isDown=false;
    p.mouseDownY=0;
    p.downY=0;

    p.init=function($dom)
    {
        this.$dom=$dom;
        this.$scrollBar=this.$dom.children(".scrollBar");
        this.$dragger=this.$dom.children(".scrollBar").children(".dragger");
        this.$bar=this.$dom.children(".scrollBar").children(".bar");
        this.$bg=this.$dom.children(".scrollBar").children(".bg");
        //
        var cur=this;
        this.$dragger.mousedown(function(event){
            cur.isDown=true;
            cur.mouseDownY=event.pageY;
            cur.downY=cur.$dragger.position().top;
        });
        $(document).mouseup(function(){
            cur.isDown=false;
        });
        this.$dom.mouseup(function(){
            if(cur.$dom.css("visibility")=="visible")
            {
                cur.$dom.animate({opacity:0},500,function(){
                    cur.$dom.css("visibility","hidden");
                });
            }
        });
        $(document).mousemove(function(event){
            if(cur.isDown){
                event.preventDefault();
                var posY=event.pageY-cur.mouseDownY+cur.downY;
                if(posY<0) posY=0;
                var bottomY=cur.$scrollBar.height()-cur.$dragger.height();
                if(posY>bottomY) posY=bottomY;
                cur.setPosition(posY);
            }
        });
        //
        this.$dom.click(function(e){
            var posY=e.pageY-$(this).offset().top;
            if(posY<0) posY=0;
            var bottomY=cur.$scrollBar.height()-cur.$dragger.height();
            if(posY>bottomY) posY=bottomY;
            cur.setPosition(posY);
        });
    };

    p.setPosition=function(posY)
    {
        this.$dragger.css("top",posY);
        this.$bg.css("height",posY);
        var per=1-this.$dragger.position().top/(this.$scrollBar.height()-this.$dragger.height());
        $(this).triggerHandler("changePer",per);
    };

    ws.VScrollBar=VScrollBar;
})()

